package com.nineclock.sign.controller;


import com.nineclock.common.entity.PageResult;
import com.nineclock.common.entity.Result;
import com.nineclock.sign.SignControllerApi;
import com.nineclock.sign.dto.SignAllUserDTO;
import com.nineclock.sign.dto.SignDTO;
import com.nineclock.sign.service.SignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.text.ParseException;
import java.util.List;

@RestController
@RequestMapping
public class SignController implements SignControllerApi {
    @Autowired
    SignService signService;

    @Override
    @GetMapping("/export")
    public void exportData(@RequestParam String startTime, @RequestParam String endTime) throws IOException {
        signService.export(startTime, endTime);
    }

    /**
     * 分页查询签到列表
     *
     * @param startTime
     * @param endTime
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/sign")
    @Override
    public Result<PageResult> querySignListRecord(@RequestParam("startTime") String startTime,
                                                  @RequestParam("endTime") String endTime,
                                                  @RequestParam("page") Integer page,
                                                  @RequestParam("pageSize") Integer pageSize) {
        PageResult pageResult = signService.querySignListRecord(startTime, endTime, page, pageSize);
        return Result.success(pageResult);
    }

    /**
     * 签到: 移动端签到
     *
     * @param signDTO
     * @return
     * @throws ParseException
     */
    @Override
    @PostMapping("/insert")
    public Result sign(SignDTO signDTO) throws ParseException {
        signService.sign(signDTO);
        return Result.success();
    }

    /**
     * @description: 当日打卡次数
     * @param:
     * @return: com.nineclock.common.entity.Result<java.lang.Integer>
     * @author 菜鸟
     * @date: 2021/7/23
     */
    @GetMapping("/getDayCount")
    public Result<Integer> getDayCount() {
        Integer count = signService.getDayCount();
        return Result.success(count);
    }

    /**
     * @description: 获取团队员工打卡列表
     * @param: dateStr
     * @return: com.nineclock.common.entity.Result<java.util.List < com.nineclock.sign.dto.SignAllUserDTO>>
     * @author 菜鸟
     * @date: 2021/7/23
     */
    @Override
    @GetMapping("/listSignAllUser")
    public Result<List<SignAllUserDTO>> getListSignAllUser(@RequestParam("dateStr") String dateStr) {
        List<SignAllUserDTO> signAllUserDTO = signService.getListSignAllUser(dateStr);
        return Result.success(signAllUserDTO);
    }



    @Override
    @GetMapping("/pagingSignCurrentUserByMonth")
    public Result<List<SignDTO>> queryHistoryCompanyUserById(String dateStr) {
        List<SignDTO> listResult = signService.queryHistory(dateStr);
        return Result.success(listResult);
    }
}
